public class LeetCode {
    public boolean backspaceCompare(String s, String t) {
        return com(s).equals(com(t));
    }
    public String com(String a){
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < a.length(); i++) {
            if(a.charAt(i)!='#'){
                sb.append(a.charAt(i));
            }else {
                if(!sb.isEmpty()){
                    sb.deleteCharAt(sb.length()-1);
                }
            }
        }
        return sb.toString();
    }
}
